package cn.edu.hrbcu.es.invigilatemanagerment.service;

import cn.edu.hrbcu.es.invigilatemanagerment.dao.PermissionMapper;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.Permission;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.PermissionExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.catalina.session.PersistentManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl implements IPermissionService{
    @Autowired
    private PermissionMapper permissionMapper;
    @Override
    public Integer insertPermission(Permission permission) {
        return permissionMapper.insert(permission);
    }

    @Override
    public Integer deletePermissionByPrimaryId(Integer permissionId) {
        return permissionMapper.deleteByPrimaryKey(permissionId);
    }

    @Override
    public Integer updatePermissionByPrimaryId(Permission permission) {
        return permissionMapper.updateByPrimaryKey(permission);
    }

    @Override
    public List<Permission> queryPermissionsByIds(List<Integer> ids) {
        return null;
    }
    @Override
    public Permission queryPermissionById(Integer id) {
        return permissionMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Permission> queryAllPermission() {
        PermissionExample permissionExample = new PermissionExample();
        PermissionExample.Criteria criteria = permissionExample.createCriteria();
        criteria.getAllCriteria();
        return permissionMapper.selectByExample(permissionExample);
    }

    @Override
    public List<Permission> selectPermissionsByTeacherId(Integer teacherId) {
        return permissionMapper.selectPermissionsByTeacherId(teacherId);
    }

    @Override
    public int queryPermissionCount() {
        PermissionExample example = new PermissionExample();
        PermissionExample.Criteria criteria = example.createCriteria();
        criteria.getAllCriteria();
        return (int) permissionMapper.countByExample(example);
    }

    @Override
    public List<Permission> queryPermissionsByPage(int pageNow, int pageSize) {
        PageHelper.startPage(pageNow,pageSize);
        List<Permission> permissions = this.queryAllPermission();
        PageInfo<Permission> permissionPageInfo = new PageInfo<>(permissions);
        return permissionPageInfo.getList();
    }
}
